package com.lazar.module1.subject3

case class UserInfo(userName: String, location: String, startTime: Int, duration: Int)

object LocationDemo {
  def main(args: Array[String]): Unit = {

    val userInfoList: List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 30),
      UserInfo("UserB", "LocationB", 10, 60),
      UserInfo("UserB", "LocationB", 11, 80)
    )

    val userMap = userInfoList.groupBy(t => t.userName + "," + t.location)  //UserA,LocationA

    val orderByUserMap = userMap.mapValues(t => t.sortBy(x => x.startTime))


    var firstTime = 0

    val totalMap = orderByUserMap.mapValues(t => {


      firstTime = t.head.startTime

      val sum = t.map(x => x.duration).sum
      sum

    })
    totalMap.foreach {
      case (datas,sunTime)=>println(s"$datas, $firstTime, $sunTime")
    }

  }
}

